package com.coming.mySpring.org.service.impl;

import com.coming.mySpring.base.service.impl.BaseServiceImpl;
import com.coming.mySpring.org.domain.Department;
import com.coming.mySpring.org.mapper.DepartmentMapper;
import com.coming.mySpring.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 删除
     * @param id
     */
    @Transactional
    @Override
    public void delete(Long id) {
        Long count = departmentMapper.findByParentId(id);
        //这里findByParentId的父级id为空才能删除,否者操作失败
        if(count == 0){
            departmentMapper.delete(id);
        }else{
            throw new RuntimeException("当前部门存在上级部门不能直接删除");
        }



    }



}
